package com.guiji.quartz.util;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ReUtil;

import java.util.Date;
import java.util.List;

/**
 * @program: cms-vue-plus
 * @description:
 * @author: gaoX
 * @create: 2021-10-14 10:53
 **/
public class DateFormatUtil {
	//Last Updated: Oct 14 2021 07:49 AM IST   Oct 10 2021 14:25  IST
	public static Date format(String s) {
		String[] split = s.split(" ");
		String day = split[1];
		String mon;
		switch (split[0]) {
			case "Jan":
				mon = "01";
				break;
			case "Feb":
				mon = "02";
				break;
			case "Mar":
				mon = "03";
				break;
			case "Apr":
				mon = "04";
				break;
			case "May":
				mon = "05";
				break;
			case "Jun":
				mon = "06";
				break;
			case "Jul":
				mon = "07";
				break;
			case "Aug":
				mon = "08";
				break;
			case "Sept":
				mon = "09";
				break;
			case "Oct":
				mon = "10";
				break;
			case "Nov":
				mon = "11";
				break;
			default:
				mon = "12";
		}
		String year = split[2];
		String sfm = split[3];
		String t = year + "-" + mon + "-" + day + " " + sfm;
		Date date = DateUtil.parse(t).toJdkDate();
		return date;
	}

	public static Date format1(String raw) {
		List<String> allGroup1 = ReUtil.findAllGroup0("Updated.*?IST", raw);
		String s = allGroup1.get(0).replaceAll("Updated:", "").trim();
		String[] split = s.split(" ");
		String day = split[0];
		String mon;
		switch (split[1]) {
			case "January":
				mon = "01";
				break;
			case "February":
				mon = "02";
				break;
			case "March":
				mon = "03";
				break;
			case "April":
				mon = "04";
				break;
			case "May":
				mon = "05";
				break;
			case "June":
				mon = "06";
				break;
			case "July":
				mon = "07";
				break;
			case "August":
				mon = "08";
				break;
			case "September":
				mon = "09";
				break;
			case "October":
				mon = "10";
				break;
			case "November":
				mon = "11";
				break;
			default:
				mon = "12";
		}
		String year = split[2];
		String sfm = split[3];
		String t = year + "-" + mon + "-" + day + " " + sfm;
		Date date = DateUtil.parse(t).toJdkDate();
		return date;
	}

}
